package com.example.shop.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.toolkit.Constants;
import com.example.shop.pojo.Courier;
import org.apache.ibatis.annotations.*;

@Mapper
public interface CourierMapper extends BaseMapper<Courier> {

    @Select("select * from courier where courier_id = ${courierId}")
    Courier selectById(long courierId);

    @Insert("insert into courier(" +
            "courier_id,courier_number,courier_type," +
            "sender_name,sender_phone,sender_area,sender_detailed_address," +
            "sender_longitude,sender_latitude," +
            "recipient_name,recipient_phone,recipient_area,recipient_detailed_address," +
            "recipient_longitude,recipient_latitude" +
            ") values(" +
            "${et.courierId},#{et.courierNumber},#{et.courierType}," +
            "#{et.senderName},#{et.senderPhone},#{et.senderArea},#{et.senderDetailedAddress}," +
            "#{et.senderLongitude},#{et.senderLatitude}," +
            "#{et.recipientName},#{et.recipientPhone},#{et.recipientArea},#{et.recipientDetailedAddress}," +
            "#{et.recipientLongitude},#{et.recipientLatitude}" +
            ")")
    int insert(@Param(Constants.ENTITY) Courier courier);


    @Update("<script>" +
            "update courier set " +
            "<if test='et.courierNumber != null'>" +
                "courier_number = ${et.courierNumber}," +
            "</if>" +
            "<if test='et.courierType != null'>" +
                "courier_type = #{et.courierType}," +
            "</if>" +
            "<if test='et.senderName != null'>" +
                "sender_name = #{et.senderName}," +
            "</if>" +
            "<if test='et.senderPhone != null'>" +
                "sender_phone = #{et.senderPhone}," +
            "</if>" +
            "<if test='et.senderArea != null'>" +
                "sender_area = #{et.senderArea}," +
            "</if>" +
            "<if test='et.senderDetailedAddress != null'>" +
                "sender_detailed_address = #{et.senderDetailedAddress}," +
            "</if>" +
            "<if test='et.senderLongitude != null'>" +
                "sender_longitude = ${et.senderLongitude}," +
            "</if>" +
            "<if test='et.senderLatitude != null'>" +
                "sender_latitude = #{et.senderLatitude}," +
            "</if>" +
            "<if test='et.recipientName != null'>" +
                "recipient_name = #{et.recipientName}," +
            "</if>" +
            "<if test='et.recipientPhone != null'>" +
                "recipient_phone = #{et.recipientPhone}," +
            "</if>" +
            "<if test='et.recipientArea != null'>" +
                "recipient_area = #{et.recipientArea}," +
            "</if>" +
            "<if test='et.recipientDetailedAddress != null'>" +
                "recipient_detailed_address = #{et.recipientDetailedAddress}," +
            "</if>" +
            "<if test='et.recipientLongitude != null'>" +
                "recipient_longitude = ${et.recipientLongitude}," +
            "</if>" +
            "<if test='et.recipientLatitude != null'>" +
                "recipient_latitude = #{et.recipientLatitude}," +
            "</if>" +
            "courier_id = courier_id " +
            "where courier_id = ${et.courierId}" +
            "</script>")
    int updateNotNull(@Param(Constants.ENTITY) Courier courier);

}
